1
The Crisis of Shared Mutable Data
AI033 Lesson 18
00:00

Imagine a software system where data flows like a ghost—haunting multiple components simultaneously. This is the Crisis of Shared Mutable Data. When Class A, B, and C all hold a reference to the same list, we encounter "spooky action at a distance." A change in one corner of the program can trigger a catastrophic failure in another, seemingly unrelated module.

1. The Ownership Dilemma

In a shared environment, the "Source of Truth" vanishes. We are forced to ask Big Questions: Who actually owns this list? What happens if Class A modifies it while Class B is halfway through a calculation? To survive, developers often resort to defensive copies (cloning data) or complex notification patterns, both of which explode in memory cost and cognitive complexity.

Mutable List[Item1, Item2, ...]Class AClass BClass CWriteReadR/W

2. Architectural Erosion

This stateful mess erodes two pillars of design: Coupling and Cohesion. High coupling occurs as classes become dangerously intertwined with the internal state of others. Cohesion weakens because a class can no longer focus on its core logic; it must now double as a "data-guard" managing external side-effects.

3. The Concurrency Wall

In our multicore world, shared mutability is the architect of race conditions. Without Immutability, safe lock-free parallel execution is mathematically impossible, as methods can never be truly independent of one another.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>